/**
 * Mixin ScriptPath
 *
 * Extracts the full url path to this script via the script tags source attribute 
 * 
 * @author David Lindkvist (david.lindkvist@shapeshift.se)
 */

PWF.mixin.ScriptPath = {

	getScriptPath: function(scriptFileName)
	{	
		//get all scripts matching this file name (no file extension)
		var scripts = this.getScriptsByName(scriptFileName);

		//always asume this is script [0] (not designed for multiple instances of same script)
		var myScript = scripts[0];
		if(myScript)
		{
			var myReg = new RegExp(scriptFileName+".js$", "g");
			var path = myScript.src.replace(myReg,'');
			
			return path;
		}	
		return "/";
	},
	getScriptsByName: function(scriptFileName)
	{
		var scripts = $A(document.getElementsByTagName("script")).findAll( function(s) 
		{
			var myReg = new RegExp(scriptFileName+".js$", "g");
			return (s.src && s.src.match(myReg));
	    });
	    
	    return scripts;
	}
};